<?php
/*
 * Aclass_nav 导航类
 * 2010-07-08
 * http://www.abans.cn		abans@qq.com
 */
class Aclass_model{
	function  __construct() {
		$this->model = Afun_db()->model(Acan_table_model);
	}
	function cache_name($name){
		return 'Amodel_'.$name;
	}

	function type($name){
		return 'text';
	}
	function data($name){
	//	$models = $this->model($name);
	}
	function model($name){
		$data = Afun_cache_get($this->cache_name($name));
		if(empty($data)){
			$model = $this->model->find("code = '$name'");
			$model_type = json_decode($model['value']);
			foreach($model_type as $v){
				$columns[$v->attr->name] = $v->type_id;
				$type[$v->type_id] = $v->attr->name;
				$value[$v->type_id] = $v->attr;
				$value[$v->type_id]->label = $v->label;
				if(!empty($v->data))
					$value[$v->type_id]->data = $v->data;
			}
			$data->id = $model['id'];
			$data->model_id = $model['model_id'];
			$data->type = $type;
			$data->columns = $columns;
			$data->data = $value;
			Afun_cache_set($this->cache_name($name),$data,3600);
		}
		return $data;
	}


}

?>
